package com.test.service.impl;

import com.test.entity.EmailLog;
import com.test.dao.EmailLogDao;
import com.test.service.EmailLogService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 邮件(EmailLog)表服务实现类
 *
 * @author makejava
 * @since 2022-11-12 11:01:47
 */
@Service("emailLogService")
public class EmailLogServiceImpl implements EmailLogService {
    @Resource
    private EmailLogDao emailLogDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public EmailLog queryById(Integer id) {
        return this.emailLogDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param emailLog 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<EmailLog> queryByPage(EmailLog emailLog, PageRequest pageRequest) {
        long total = this.emailLogDao.count(emailLog);
        return new PageImpl<>(this.emailLogDao.queryAllByLimit(emailLog, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param emailLog 实例对象
     * @return 实例对象
     */
    @Override
    public EmailLog insert(EmailLog emailLog) {
        this.emailLogDao.insert(emailLog);
        return emailLog;
    }

    /**
     * 修改数据
     *
     * @param emailLog 实例对象
     * @return 实例对象
     */
    @Override
    public EmailLog update(EmailLog emailLog) {
        this.emailLogDao.update(emailLog);
        return this.queryById(emailLog.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.emailLogDao.deleteById(id) > 0;
    }
}
